<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="https://gitee.com/reku1997/reku1997/raw/master/reku.ico">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"reku1997.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"appID":"AW5K8S9IEE","apiKey":"d7e666d597854738d2fb31ecaa989aa5","indexName":"dev_reku1997","hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="http:&#x2F;&#x2F;codeforces.com&#x2F;problemset&#x2F;problem&#x2F;89&#x2F;C 网状链表模拟...有点难写... 内存有可能开不下，要分类讨论一下内存...">
<meta property="og:type" content="article">
<meta property="og:title" content="近期题目">
<meta property="og:url" content="https://reku1997.gitee.io/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/index.html">
<meta property="og:site_name" content="Reku">
<meta property="og:description" content="http:&#x2F;&#x2F;codeforces.com&#x2F;problemset&#x2F;problem&#x2F;89&#x2F;C 网状链表模拟...有点难写... 内存有可能开不下，要分类讨论一下内存...">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2016-10-30T02:39:04.000Z">
<meta property="article:modified_time" content="2020-06-09T12:01:18.000Z">
<meta property="article:author" content="Reku">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://reku1997.gitee.io/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-cn'
  };
</script>

  <title>近期题目 | Reku</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Reku" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Reku</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>Sitemap</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container"></div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="algolia-results">
  <div id="algolia-stats"></div>
  <div id="algolia-hits"></div>
  <div id="algolia-pagination" class="algolia-pagination"></div>
</div>

      
    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-cn">
    <link itemprop="mainEntityOfPage" href="https://reku1997.gitee.io/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Reku">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Reku">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          近期题目
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2016-10-30 10:39:04" itemprop="dateCreated datePublished" datetime="2016-10-30T10:39:04+08:00">2016-10-30</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2020-06-09 20:01:18" itemprop="dateModified" datetime="2020-06-09T20:01:18+08:00">2020-06-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/acm/" itemprop="url" rel="index"><span itemprop="name">acm</span></a>
                </span>
            </span>

          
            <span id="/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/" class="post-meta-item leancloud_visitors" data-flag-title="近期题目" title="Views">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">Views: </span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine: </span>
    
    <a title="valine" href="/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2016/10/30/%E8%BF%91%E6%9C%9F%E9%A2%98%E7%9B%AE-2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><a target="_blank" rel="noopener" href="http://codeforces.com/problemset/problem/89/C">http://codeforces.com/problemset/problem/89/C</a> 网状链表模拟...有点难写... 内存有可能开不下，要分类讨论一下内存...</p>
<span id="more"></span>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="keyword">char</span> c[<span class="number">5010</span>][<span class="number">5010</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">short</span> p[<span class="number">5001</span>][<span class="number">550</span>][<span class="number">4</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">short</span> q[<span class="number">5001</span>][<span class="number">550</span>][<span class="number">4</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">short</span> pi[<span class="number">550</span>][<span class="number">5001</span>][<span class="number">4</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">short</span> qi[<span class="number">550</span>][<span class="number">5001</span>][<span class="number">4</span>]=&#123;&#125;;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">int</span> t=i<span class="number">-1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&gt;=<span class="number">1</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[t][j]==<span class="string">&#x27;.&#x27;</span>) t--;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					p[i][j][<span class="number">0</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			t=i+<span class="number">1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&lt;=n)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[t][j]==<span class="string">&#x27;.&#x27;</span>) t++;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					p[i][j][<span class="number">1</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			t=j<span class="number">-1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&gt;=<span class="number">1</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][t]==<span class="string">&#x27;.&#x27;</span>) t--;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					p[i][j][<span class="number">2</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				 &#125; </span><br><span class="line">			&#125;</span><br><span class="line">			t=j+<span class="number">1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&lt;=m)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][t]==<span class="string">&#x27;.&#x27;</span>) t++;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					p[i][j][<span class="number">3</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pp</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k&lt;=<span class="number">3</span>;k++)</span><br><span class="line">			&#123;</span><br><span class="line">				q[i][j][k]=p[i][j][k];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">ff</span><span class="params">(<span class="keyword">int</span> x,<span class="keyword">int</span> y)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="built_in">pp</span>();</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		ans++;</span><br><span class="line">		<span class="keyword">int</span> w;</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;U&#x27;</span>) w=q[x][y][<span class="number">0</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;D&#x27;</span>) w=q[x][y][<span class="number">1</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;L&#x27;</span>) w=q[x][y][<span class="number">2</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;R&#x27;</span>) w=q[x][y][<span class="number">3</span>];</span><br><span class="line">		<span class="keyword">if</span>(w==<span class="number">0</span>) <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">int</span> e[<span class="number">4</span>];</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;=<span class="number">3</span>;i++) e[i]=q[x][y][i];</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">0</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			q[e[<span class="number">0</span>]][y][<span class="number">1</span>]=e[<span class="number">1</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">1</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			q[e[<span class="number">1</span>]][y][<span class="number">0</span>]=e[<span class="number">0</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">2</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			q[x][e[<span class="number">2</span>]][<span class="number">3</span>]=e[<span class="number">3</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">3</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			q[x][e[<span class="number">3</span>]][<span class="number">2</span>]=e[<span class="number">2</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;U&#x27;</span>) x=e[<span class="number">0</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;D&#x27;</span>) x=e[<span class="number">1</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;L&#x27;</span>) y=e[<span class="number">2</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;R&#x27;</span>) y=e[<span class="number">3</span>];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init1</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">int</span> t=i<span class="number">-1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&gt;=<span class="number">1</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[t][j]==<span class="string">&#x27;.&#x27;</span>) t--;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					pi[i][j][<span class="number">0</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			t=i+<span class="number">1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&lt;=n)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[t][j]==<span class="string">&#x27;.&#x27;</span>) t++;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					pi[i][j][<span class="number">1</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			t=j<span class="number">-1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&gt;=<span class="number">1</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][t]==<span class="string">&#x27;.&#x27;</span>) t--;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					pi[i][j][<span class="number">2</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				 &#125; </span><br><span class="line">			&#125;</span><br><span class="line">			t=j+<span class="number">1</span>;</span><br><span class="line">			<span class="keyword">while</span>(t&lt;=m)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][t]==<span class="string">&#x27;.&#x27;</span>) t++;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					pi[i][j][<span class="number">3</span>]=t;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pp1</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k&lt;=<span class="number">3</span>;k++)</span><br><span class="line">			&#123;</span><br><span class="line">				qi[i][j][k]=pi[i][j][k];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">ff1</span><span class="params">(<span class="keyword">int</span> x,<span class="keyword">int</span> y)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="built_in">pp1</span>();</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		ans++;</span><br><span class="line">		<span class="keyword">int</span> w;</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;U&#x27;</span>) w=qi[x][y][<span class="number">0</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;D&#x27;</span>) w=qi[x][y][<span class="number">1</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;L&#x27;</span>) w=qi[x][y][<span class="number">2</span>];</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;R&#x27;</span>) w=qi[x][y][<span class="number">3</span>];</span><br><span class="line">		<span class="keyword">if</span>(w==<span class="number">0</span>) <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">int</span> e[<span class="number">4</span>];</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;=<span class="number">3</span>;i++) e[i]=qi[x][y][i];</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">0</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			qi[e[<span class="number">0</span>]][y][<span class="number">1</span>]=e[<span class="number">1</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">1</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			qi[e[<span class="number">1</span>]][y][<span class="number">0</span>]=e[<span class="number">0</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">2</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			qi[x][e[<span class="number">2</span>]][<span class="number">3</span>]=e[<span class="number">3</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(e[<span class="number">3</span>]!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			qi[x][e[<span class="number">3</span>]][<span class="number">2</span>]=e[<span class="number">2</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;U&#x27;</span>) x=e[<span class="number">0</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;D&#x27;</span>) x=e[<span class="number">1</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;L&#x27;</span>) y=e[<span class="number">2</span>];</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c[x][y]==<span class="string">&#x27;R&#x27;</span>) y=e[<span class="number">3</span>];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">char</span> cc;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d%d&quot;</span>,&amp;n,&amp;m);</span><br><span class="line">	cc=<span class="built_in">getchar</span>();</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			cc=<span class="built_in">getchar</span>();</span><br><span class="line">			c[i][j]=cc;</span><br><span class="line">		&#125;</span><br><span class="line">		cc=<span class="built_in">getchar</span>();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">int</span> ansx=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">int</span> ansy=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">if</span>(n&gt;=m)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">init</span>();</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][j]==<span class="string">&#x27;.&#x27;</span>) <span class="keyword">continue</span>;</span><br><span class="line">				<span class="keyword">int</span> tt=<span class="built_in">ff</span>(i,j);</span><br><span class="line">				<span class="keyword">if</span>(tt&gt;ansx)</span><br><span class="line">				&#123;</span><br><span class="line">					ansx=tt;</span><br><span class="line">					ansy=<span class="number">1</span>;</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">else</span> <span class="keyword">if</span>(tt==ansx)</span><br><span class="line">				&#123;</span><br><span class="line">					ansy++;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">init1</span>();</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=m;j++)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(c[i][j]==<span class="string">&#x27;.&#x27;</span>) <span class="keyword">continue</span>;</span><br><span class="line">				<span class="keyword">int</span> tt=<span class="built_in">ff1</span>(i,j);</span><br><span class="line">				<span class="keyword">if</span>(tt&gt;ansx)</span><br><span class="line">				&#123;</span><br><span class="line">					ansx=tt;</span><br><span class="line">					ansy=<span class="number">1</span>;</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">else</span> <span class="keyword">if</span>(tt==ansx)</span><br><span class="line">				&#123;</span><br><span class="line">					ansy++;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%d %d&quot;</span>,ansx,ansy);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://codeforces.com/problemset/problem/277/C">http://codeforces.com/problemset/problem/277/C</a> 还算挺有意思的一个博弈论。 本质上我们发现，每一条线就相当于nim游戏中的一堆石子。 然后当ans^a[i]&lt;=a[i]时，我们可以在这堆石子上取，证明比较显然... 依然很难写...</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string">&lt;int,int&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pb push_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mk make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> x first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> y second</span></span><br><span class="line"><span class="keyword">int</span> n,m,k;</span><br><span class="line">map&lt;<span class="keyword">int</span>,vector&lt;PII &gt; &gt; lie;</span><br><span class="line">map&lt;<span class="keyword">int</span>,vector&lt;PII &gt; &gt; ha;</span><br><span class="line">map&lt;<span class="keyword">int</span>,<span class="keyword">bool</span>&gt; vl;</span><br><span class="line">map&lt;<span class="keyword">int</span>,<span class="keyword">bool</span>&gt; vh;</span><br><span class="line">map&lt;<span class="keyword">int</span>,<span class="keyword">int</span>&gt; hl;</span><br><span class="line">map&lt;<span class="keyword">int</span>,<span class="keyword">int</span>&gt; hh;</span><br><span class="line"><span class="keyword">int</span> xa,ya,xb,yb;</span><br><span class="line"><span class="keyword">int</span> hhh=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> ll=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d%d%d&quot;</span>,&amp;n,&amp;m,&amp;k);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=k;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">scanf</span>(<span class="string">&quot;%d%d%d%d&quot;</span>,&amp;xa,&amp;ya,&amp;xb,&amp;yb);</span><br><span class="line">		<span class="keyword">if</span>(xa==xb)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(vl.<span class="built_in">find</span>(xa)==vl.<span class="built_in">end</span>()) vl[xa]=<span class="number">1</span>,ll++;</span><br><span class="line">			<span class="keyword">if</span>(ya&gt;yb) <span class="built_in">swap</span>(ya,yb);</span><br><span class="line">			lie[xa].<span class="built_in">pb</span>(<span class="built_in">mk</span>(ya,yb));</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(vh.<span class="built_in">find</span>(ya)==vh.<span class="built_in">end</span>()) vh[ya]=<span class="number">1</span>,hhh++;</span><br><span class="line">			<span class="keyword">if</span>(xa&gt;xb) <span class="built_in">swap</span>(xa,xb);</span><br><span class="line">			ha[ya].<span class="built_in">pb</span>(<span class="built_in">mk</span>(xa,xb));</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	ll=n<span class="number">-1</span>-ll;</span><br><span class="line">	hhh=m<span class="number">-1</span>-hhh;</span><br><span class="line">	<span class="keyword">if</span>(ll%<span class="number">2</span>) ans^=m;</span><br><span class="line">	<span class="keyword">if</span>(hhh%<span class="number">2</span>) ans^=n;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(vl.<span class="built_in">find</span>(i)==vl.<span class="built_in">end</span>())</span><br><span class="line">		&#123;</span><br><span class="line">			hl[i]=m;</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;m;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(vh.<span class="built_in">find</span>(i)==vh.<span class="built_in">end</span>())</span><br><span class="line">		&#123;</span><br><span class="line">			hh[i]=n;</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">auto</span> &amp;i: lie)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">sort</span>(i.y.<span class="built_in">begin</span>(),i.y.<span class="built_in">end</span>());</span><br><span class="line">		<span class="keyword">int</span> pp=<span class="number">0</span>;</span><br><span class="line">		pp=i.y[<span class="number">0</span>].y-i.y[<span class="number">0</span>].x;</span><br><span class="line">		<span class="keyword">int</span> tt=i.y[<span class="number">0</span>].y;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k&lt;i.y.<span class="built_in">size</span>();k++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(i.y[k].x&lt;=tt)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(i.y[k].y&gt;tt) pp+=i.y[k].y-tt,tt=i.y[k].y;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">else</span></span><br><span class="line">			&#123;</span><br><span class="line">				pp+=i.y[k].y-i.y[k].x;</span><br><span class="line">				tt=i.y[k].y;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		hl[i.x]=m-pp;</span><br><span class="line">		ans^=(m-pp);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">auto</span> &amp;i: ha)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">sort</span>(i.y.<span class="built_in">begin</span>(),i.y.<span class="built_in">end</span>());</span><br><span class="line">		<span class="keyword">int</span> pp=<span class="number">0</span>;</span><br><span class="line">		pp=i.y[<span class="number">0</span>].y-i.y[<span class="number">0</span>].x;</span><br><span class="line">		<span class="keyword">int</span> tt=i.y[<span class="number">0</span>].y;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k&lt;i.y.<span class="built_in">size</span>();k++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(i.y[k].x&lt;=tt)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(i.y[k].y&gt;tt) pp+=i.y[k].y-tt,tt=i.y[k].y;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">else</span></span><br><span class="line">			&#123;</span><br><span class="line">				pp+=i.y[k].y-i.y[k].x;</span><br><span class="line">				tt=i.y[k].y;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		hh[i.x]=n-pp;</span><br><span class="line">		ans^=(n-pp);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span>(ans)</span><br><span class="line">	&#123;</span><br><span class="line">		cout&lt;&lt;<span class="string">&quot;FIRST&quot;</span>&lt;&lt;endl;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">auto</span> &amp;i: hh)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">int</span> pp=ans^i.second;</span><br><span class="line">			<span class="keyword">if</span>(pp&lt;=i.second)</span><br><span class="line">			&#123;</span><br><span class="line">				pp=i.second-pp;</span><br><span class="line">				<span class="keyword">if</span>(ha.<span class="built_in">find</span>(i.x)==ha.<span class="built_in">end</span>())</span><br><span class="line">				&#123;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d %d %d %d\n&quot;</span>,<span class="number">0</span>,i.x,pp,i.x);</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d %d &quot;</span>,<span class="number">0</span>,i.x);</span><br><span class="line">					<span class="keyword">int</span> yy=<span class="number">0</span>;</span><br><span class="line">					<span class="keyword">if</span>(ha[i.x][<span class="number">0</span>].x&gt;=pp)</span><br><span class="line">					&#123;</span><br><span class="line">						<span class="built_in">printf</span>(<span class="string">&quot;%d %d\n&quot;</span>,pp,i.x);</span><br><span class="line">						<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">					&#125;</span><br><span class="line">					yy=ha[i.x][<span class="number">0</span>].x;</span><br><span class="line">					pp-=yy;</span><br><span class="line">					yy=ha[i.x][<span class="number">0</span>].y;</span><br><span class="line">					<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k&lt;ha[i.x].<span class="built_in">size</span>();k++)</span><br><span class="line">					&#123;</span><br><span class="line">						<span class="keyword">if</span>(ha[i.x][k].x&lt;=yy)</span><br><span class="line">						&#123;</span><br><span class="line">							yy=<span class="built_in">max</span>(yy,ha[i.x][k].y);</span><br><span class="line">						&#125;</span><br><span class="line">						<span class="keyword">else</span></span><br><span class="line">						&#123;</span><br><span class="line">							<span class="keyword">if</span>(ha[i.x][k].x-yy&gt;=pp)</span><br><span class="line">							&#123;</span><br><span class="line">								yy+=pp;</span><br><span class="line">								<span class="built_in">printf</span>(<span class="string">&quot;%d %d\n&quot;</span>,yy,i.x);</span><br><span class="line">								<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">							&#125;</span><br><span class="line">							<span class="keyword">else</span></span><br><span class="line">							&#123;</span><br><span class="line">								pp-=ha[i.x][k].x-yy;</span><br><span class="line">								yy=<span class="built_in">max</span>(yy,ha[i.x][k].y);</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;</span><br><span class="line">					&#125;</span><br><span class="line">					yy+=pp;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d %d\n&quot;</span>,yy,i.x);</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">auto</span> &amp;i: hl)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">int</span> pp=ans^i.second;</span><br><span class="line">			<span class="keyword">if</span>(pp&lt;=i.second)</span><br><span class="line">			&#123;</span><br><span class="line">				pp=i.second-pp;</span><br><span class="line">				<span class="keyword">if</span>(lie.<span class="built_in">find</span>(i.x)==lie.<span class="built_in">end</span>())</span><br><span class="line">				&#123;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d %d %d %d\n&quot;</span>,i.x,<span class="number">0</span>,i.x,pp);</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">				&#123;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d %d %d &quot;</span>,i.x,<span class="number">0</span>,i.x);</span><br><span class="line">					<span class="keyword">int</span> yy=<span class="number">0</span>;</span><br><span class="line">					<span class="keyword">if</span>(lie[i.x][<span class="number">0</span>].x&gt;=pp)</span><br><span class="line">					&#123;</span><br><span class="line">						<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,pp);</span><br><span class="line">						<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">					&#125;</span><br><span class="line">					yy=lie[i.x][<span class="number">0</span>].x;</span><br><span class="line">					pp-=yy;</span><br><span class="line">					yy=lie[i.x][<span class="number">0</span>].y;</span><br><span class="line">					<span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k&lt;lie[i.x].<span class="built_in">size</span>();k++)</span><br><span class="line">					&#123;</span><br><span class="line">						<span class="comment">//cout&lt;&lt;yy&lt;&lt;&quot; ******&quot;&lt;&lt;&quot; &quot;&lt;&lt;lie[i.x][k].x&lt;&lt;&quot; &quot;&lt;&lt;lie[i.x][k].y&lt;&lt;endl;</span></span><br><span class="line">						<span class="keyword">if</span>(lie[i.x][k].x&lt;=yy)</span><br><span class="line">						&#123;</span><br><span class="line">							yy=<span class="built_in">max</span>(yy,lie[i.x][k].y);</span><br><span class="line">						&#125;</span><br><span class="line">						<span class="keyword">else</span></span><br><span class="line">						&#123;</span><br><span class="line">							<span class="keyword">if</span>(lie[i.x][k].x-yy&gt;=pp)</span><br><span class="line">							&#123;</span><br><span class="line">								yy+=pp;</span><br><span class="line">								<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,yy);</span><br><span class="line">								<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">							&#125;</span><br><span class="line">							<span class="keyword">else</span></span><br><span class="line">							&#123;</span><br><span class="line">								pp-=lie[i.x][k].x-yy;</span><br><span class="line">								yy=<span class="built_in">max</span>(yy,lie[i.x][k].y);</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;</span><br><span class="line">					&#125;</span><br><span class="line">					yy+=pp;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,yy);</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span> cout&lt;&lt;<span class="string">&quot;SECOND&quot;</span>&lt;&lt;endl;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://codeforces.com/problemset/problem/476/E">http://codeforces.com/problemset/problem/476/E</a> 挺有趣的一个DP dp[i][j]代表走了前i个字符，删去了j个字符，最多匹配了多少个串。 对于每一个位置，我们可以知道删去多少个字符，可以出现一个最近的匹配串。 这样的话，暴力转移就好了。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">int</span> dp[<span class="number">2010</span>][<span class="number">2010</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">char</span> a[<span class="number">2010</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">char</span> p[<span class="number">2010</span>]=&#123;&#125;;</span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">ff</span><span class="params">(<span class="keyword">int</span> x)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">if</span>(x&lt;m) <span class="keyword">return</span> <span class="number">2147483600</span>;</span><br><span class="line">	<span class="keyword">int</span> t=m;</span><br><span class="line">	<span class="keyword">int</span> b=x;</span><br><span class="line">	<span class="keyword">int</span> tp=<span class="number">0</span>;</span><br><span class="line">	<span class="comment">//cout&lt;&lt;x&lt;&lt;&quot; ****&quot;&lt;&lt;endl;</span></span><br><span class="line">	<span class="keyword">while</span>(t&amp;&amp;b)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(p[t]==a[b]) t--,b--;</span><br><span class="line">		<span class="keyword">else</span> tp++,b--;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span>(t==<span class="number">0</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">return</span> x-b-m;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="number">2147483600</span>;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,a+<span class="number">1</span>);</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,p+<span class="number">1</span>);</span><br><span class="line">	n=<span class="built_in">strlen</span>(a+<span class="number">1</span>);</span><br><span class="line">	m=<span class="built_in">strlen</span>(p+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=i+<span class="number">1</span>;j&lt;=n;j++) dp[i][j]=<span class="number">-2147483600</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">int</span> k=<span class="built_in">ff</span>(i);</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;=n;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			dp[i][j]=<span class="built_in">max</span>(dp[i][j],dp[i<span class="number">-1</span>][j]);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;=n;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(j&gt;=k) dp[i][j]=<span class="built_in">max</span>(dp[i][j],dp[i-k-m][j-k]+<span class="number">1</span>);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,dp[n][i]);</span><br><span class="line">		<span class="keyword">if</span>(i!=n) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://codeforces.com/problemset/problem/190/E">http://codeforces.com/problemset/problem/190/E</a> 补图上的bfs，是一个挺常见的套路... 但是时间复杂度还不是很懂...</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="keyword">int</span> a,b;</span><br><span class="line">vector&lt;<span class="keyword">int</span>&gt; ha[<span class="number">500010</span>];</span><br><span class="line">set&lt;<span class="keyword">int</span>&gt; s;</span><br><span class="line"><span class="keyword">int</span> tt=<span class="number">0</span>;</span><br><span class="line">queue&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">vector&lt;<span class="keyword">int</span>&gt; e[<span class="number">500010</span>];</span><br><span class="line">queue&lt;<span class="keyword">int</span>&gt; o;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">cmp</span><span class="params">(<span class="keyword">int</span> x,<span class="keyword">int</span> y)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">return</span> x&lt;y;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">bfs</span><span class="params">(<span class="keyword">int</span> x)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">while</span>(!q.<span class="built_in">empty</span>()) q.<span class="built_in">pop</span>();</span><br><span class="line">	<span class="keyword">while</span>(!o.<span class="built_in">empty</span>()) o.<span class="built_in">pop</span>();</span><br><span class="line">	tt++;</span><br><span class="line">	q.<span class="built_in">push</span>(x);</span><br><span class="line">	s.<span class="built_in">erase</span>(x);</span><br><span class="line">	<span class="keyword">while</span>(!q.<span class="built_in">empty</span>())</span><br><span class="line">	&#123;</span><br><span class="line">		x=q.<span class="built_in">front</span>();</span><br><span class="line">		e[tt].<span class="built_in">push_back</span>(x);</span><br><span class="line">		q.<span class="built_in">pop</span>();</span><br><span class="line">		<span class="keyword">int</span> w=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">auto</span> &amp;i: s)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(ha[x].<span class="built_in">size</span>()!=<span class="number">0</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">while</span>(w+<span class="number">1</span>!=ha[x].<span class="built_in">size</span>())</span><br><span class="line">				&#123;</span><br><span class="line">					<span class="keyword">if</span>(i&gt;ha[x][w]) w++;</span><br><span class="line">					<span class="keyword">else</span> <span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">if</span>(i!=ha[x][w])</span><br><span class="line">				&#123;</span><br><span class="line">					q.<span class="built_in">push</span>(i);</span><br><span class="line">					o.<span class="built_in">push</span>(i);</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">else</span></span><br><span class="line">			&#123;</span><br><span class="line">				q.<span class="built_in">push</span>(i);</span><br><span class="line">				o.<span class="built_in">push</span>(i);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">while</span>(!o.<span class="built_in">empty</span>()) s.<span class="built_in">erase</span>(o.<span class="built_in">front</span>()),o.<span class="built_in">pop</span>();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d%d&quot;</span>,&amp;n,&amp;m);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=m;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">scanf</span>(<span class="string">&quot;%d%d&quot;</span>,&amp;a,&amp;b);</span><br><span class="line">		ha[a].<span class="built_in">push_back</span>(b);</span><br><span class="line">		ha[b].<span class="built_in">push_back</span>(a);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(ha[i].<span class="built_in">size</span>()!=<span class="number">0</span>) <span class="built_in">sort</span>(ha[i].<span class="built_in">begin</span>(),ha[i].<span class="built_in">end</span>(),cmp);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++) s.<span class="built_in">insert</span>(i);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(s.<span class="built_in">find</span>(i)!=s.<span class="built_in">end</span>()) <span class="built_in">bfs</span>(i);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,tt);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=tt;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>,e[i].<span class="built_in">size</span>());</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;e[i].<span class="built_in">size</span>();j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>,e[i][j]);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2016/10/20/codeforces-round-140-div-1-c-anniversary/" rel="prev" title="Codeforces Round #140 (Div. 1) C. Anniversary">
      <i class="fa fa-chevron-left"></i> Codeforces Round #140 (Div. 1) C. Anniversary
    </a></div>
      <div class="post-nav-item">
    <a href="/2016/12/22/%E5%90%8E%E7%BC%80%E6%95%B0%E7%BB%84%E5%A4%8D%E4%B9%A0/" rel="next" title="后缀数组复习">
      后缀数组复习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Reku</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">96</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/wyc-ruiker" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyc-ruiker" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/reku1997" title="ZhiHu → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;reku1997" rel="noopener" target="_blank"><i class="fa fa-fw fa-quora"></i>ZhiHu</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://codeforces.com/profile/reku" title="CodeForces → http:&#x2F;&#x2F;codeforces.com&#x2F;profile&#x2F;reku" rel="noopener" target="_blank"><i class="fa fa-fw fa-code"></i>CodeForces</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.linkedin.cn/injobs/in/reku" title="Linkedin → https:&#x2F;&#x2F;www.linkedin.cn&#x2F;injobs&#x2F;in&#x2F;reku" rel="noopener" target="_blank"><i class="fa fa-fw fa-linkedin"></i>Linkedin</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/reku1997" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;reku1997" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="/./atom.xml" title="RSS → .&#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2016 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Reku</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="//cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script>
<script src="//cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script>
<script src="/js/algolia-search.js"></script>














  

  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'MWLzM550UOu69h3dgvbbLSsF-gzGzoHsz',
      appKey     : 'gkKnwm9FK0cu3ysJbcggsCDz',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
